home *** CD-ROM | disk | FTP | other *** search
/ 5 Star Games: DOS Edition 2 / 5 Star Games - DOS Edition (1995)(Ready to Run).iso / dbc / db_dosh.asm < prev    next >
Assembly Source File  |  1992-02-28  |  4KB  |  169 lines

  1. dosseg
  2. locals
  3.  
  4. .model    huge
  5.  
  6. .code
  7.  
  8. ;-----------------------------------------------------------------------------
  9. ; void swinterrupt(byte intno, db_regs *inregs, db_regs *outregs);
  10. ;-----------------------------------------------------------------------------
  11. public        _swinterrupt
  12.  
  13. db_regs        struc
  14. rax        dw    ?
  15. rbx        dw    ?
  16. rcx        dw    ?
  17. rdx        dw    ?
  18. rsi        dw    ?
  19. rdi        dw    ?
  20. rcflag        dw    ?
  21. rflags        dw    ?
  22. db_regs        ends
  23.  
  24. _swinterrupt    proc
  25. arg    intno:byte,inregs:dword,outregs:dword
  26.         push    bp
  27.         mov    bp,sp            ; link stack
  28.         push    si            ; save regs
  29.         push    di
  30.         push    ds
  31.         mov    al,intno        ; set interrupt number
  32.         mov    cs:no,al
  33.         lds    bx,inregs        ; get source regs
  34.         mov    ax,[bx].rax        ; load regs
  35.         mov    cx,[bx].rcx
  36.         mov    dx,[bx].rdx
  37.         mov    si,[bx].rsi
  38.         mov    di,[bx].rdi
  39.         mov    bx,[bx].rbx
  40. intr        db    0CDh            ; int
  41. no        db    ?            ; int number
  42.         push    bx            ; save return reg BX
  43.         lds    bx,outregs        ; get dest regs
  44.         mov    [bx].rax,ax        ; set return regs
  45.         pop    ax            ; restore return reg BX
  46.         mov    [bx].rbx,ax
  47.         mov    [bx].rcx,cx
  48.         mov    [bx].rdx,dx
  49.         mov    [bx].rsi,si
  50.         mov    [bx].rdi,di
  51.         pushf                ; set flags
  52.         pop    ax
  53.         mov    [bx].rflags,ax
  54.         and    ax,0001h
  55.         mov    [bx].rcflag,ax
  56.         pop    ds            ; restore regs
  57.         pop    di
  58.         pop    si
  59.         pop    bp
  60.         ret
  61. _swinterrupt    endp
  62.  
  63. ;-----------------------------------------------------------------------------
  64. ; void db_delay(word msecs);
  65. ;-----------------------------------------------------------------------------
  66. public        _db_delay
  67.  
  68. msecspertick    dw    55        ; number of msecs in one timer tick
  69. delaycount    dw    0        ; 1ms delay count
  70.  
  71. _db_delay    proc
  72. arg    msecs:word
  73.         push    bp            ; link stack
  74.         mov    bp,sp
  75.         push    ds
  76.         cmp    cs:delaycount,0        ; see if been initialized
  77.         jne    @@dodelay        ; y
  78.         xor    dx,dx            ; init hi word of count
  79.         mov    ds,dx            ; point at system tick count
  80.         mov    bx,46Ch            ; 0000:046Ch
  81. @@synch1:    test    byte ptr [bx],1        ; wait for 1
  82.         jz    @@synch1
  83. @@synch2:    test    byte ptr [bx],1        ; wait for 0
  84.         jnz    @@synch2
  85. @@start:    xor    cx,cx
  86. even
  87. @@timing:    test    byte ptr [bx],1        ; loop while still 0
  88.         jnz    @@stop            ; done
  89.         loop    @@timing        ; keep timing
  90.         inc    dx            ; keep overflow
  91.         jmp    short @@start
  92.  
  93. @@stop:        xor    ax,ax            ; calc number done
  94.         sub    ax,cx
  95.         div    cs:msecspertick        ; calc delay wait
  96.         mov    cs:delaycount,ax    ; save
  97. @@dodelay:    mov    cx,msecs        ; get number of msecs to wait
  98.         jcxz    @@exit            ; exit if no wait
  99.         push    cs            ; setup DS:BX to point at a
  100.         pop    ds            ; guaranteed non-zero value
  101.         mov    bx,offset msecspertick
  102. @@delay:    push    cx
  103.         mov    cx,cs:delaycount    ; get delay count
  104. even
  105. @@delay1ms:    test    byte ptr [bx],0FFh    ; test to simulate same timing
  106.         je    @@bogus            ; this should never branch
  107.         loop    @@delay1ms
  108. @@bogus:    pop    cx
  109.         loop    @@delay
  110. @@exit:        pop    ds            ; done
  111.         pop    bp
  112.         ret
  113. _db_delay    endp
  114.  
  115. ;-----------------------------------------------------------------------------
  116. ; void db_sound(word freq);
  117. ;-----------------------------------------------------------------------------
  118. public        _db_sound
  119.  
  120. PPI_B        equ    61h        ; PPI port B
  121. speaker_on    equ    03h        ; speaker control bits
  122. TIMER_2        equ    42h        ; speaker timer count reg
  123. TIMER_MODE    equ    43h        ; timer mode reg
  124. sound_mode    equ    0B6h        ; timer 2 select, word count, binary
  125. clock_hi    equ    0012h        ; input clock speed of 1,193,180 Hz
  126. clock_lo    equ    34DCh
  127.  
  128. _db_sound    proc
  129. arg    freq:word
  130.         push    bp            ; link stack
  131.         mov    bp,sp
  132.         xor    ax,ax            ; set min freq limit
  133.         mov    cx,freq            ; get frequency required in Hz
  134.         mov    dx,clock_hi        ; set hi word 1 Hz divisor
  135.         cmp    dx,cx            ; check if below min freq
  136.         jae    @@settimer        ; y - set to minimum Hz
  137.         mov    ax,clock_lo        ; n - set lo word 1 Hz divisor
  138.         div    cx            ; calc required divisor
  139. @@settimer:    mov    bx,ax            ; save divisor
  140.         mov    al,sound_mode        ; setup timer channel 2
  141.         out    TIMER_MODE,al
  142.         mov    al,bl            ; timer 2 LSB
  143.         out    TIMER_2,al
  144.         mov    al,bh            ; timer 2 MSB
  145.         out    TIMER_2,al
  146.         in    al,PPI_B        ; enable speaker
  147.         or    al,speaker_on
  148.         out    PPI_B,al
  149.         pop    bp
  150.         ret
  151. _db_sound    endp
  152.  
  153. ;-----------------------------------------------------------------------------
  154. ; void db_nosound(void);
  155. ;-----------------------------------------------------------------------------
  156. public        _db_nosound
  157.  
  158. _db_nosound    proc
  159.         in    al,PPI_B        ; get PPI
  160.         and    al,not speaker_on    ; mask off speaker
  161.         out    PPI_B,al        ; set PPI
  162.         ret
  163. _db_nosound    endp
  164.  
  165. ;-----------------------------------------------------------------------------
  166.  
  167. end
  168.  
  169.